var vant = window.vant;
var qsd = querystring.parse();
var cfg = new AppCfg().init({
	isDebug: false,
});
var orderno=qsd.orderno?qsd.orderno:'';
var ordertype=qsd.ordertype?qsd.ordertype:'';
function onBridgeReady() {
	var param = {
		order_no: qsd.orderno,
		total_fee: qsd.amount,
	}
	cfg.majaxAction("unifiedOrder", param, function(ret) {
		var resdata = ret.data;
		console.log(resdata);
		WeixinJSBridge.invoke(
			'getBrandWCPayRequest', {
				"appId": resdata.appId, //公众号名称，由商户传入     
				"timeStamp": resdata.timeStamp, //时间戳，自1970年以来的秒数     
				"nonceStr": resdata.nonceStr, //随机串     
				"package": resdata.package,
				"signType": resdata.signType, //微信签名方式：     
				"paySign": resdata.paySign //微信签名 
			},
			function(res) {
				if (res.err_msg == "get_brand_wcpay_request:ok") {
					// window.location.href = 'paysuccess.html?orderno='+orderno+'&ordertype='+ordertype;
					window.location.href='paysuccess.html';
				}
// 				else if(res.err_msg == "get_brand_wcpay_request:cancel"){
// 					// vant.Toast('支付失败')
// 				}else if(res.err_msg == "get_brand_wcpay_request:fail"){
// 					vant.Toast('支付失败')
// 				}
			});
	})
}

function callpay() {
	if (typeof WeixinJSBridge == "undefined") {
		if (document.addEventListener) {
			document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
		} else if (document.attachEvent) {
			document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
			document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
		}
	} else {
		onBridgeReady();
	}
}
